import { System, World } from '@ecs/core'
import { TestComponent1, TestComponent2, TestComponent3 } from './components'

export class TestSystem extends System {
  constructor(public count: number) {
    super()
  }

  public update(world: World): void {
    for (const [, componentMap] of world.view(TestComponent1)) {
      const test1 = componentMap.get(TestComponent1)
      test1.b = this.count
    }
    for (const [, componentMap] of world.view(TestComponent1, TestComponent2)) {
      const test1 = componentMap.get(TestComponent1)
      test1.b = -this.count
    }
    for (const [, componentMap] of world.view(TestComponent1, TestComponent3)) {
      const test1 = componentMap.get(TestComponent1)
      test1.b = 0
    }
    for (const [, componentMap] of world.view(
      TestComponent1,
      TestComponent2,
      TestComponent3
    )) {
      const test1 = componentMap.get(TestComponent1)
      test1.b = this.count * 2
    }
  }

  public destory(world: World): void {
    for (const [entity] of world.view(TestComponent1)) {
      world.removeEntity(entity)
    }
  }
}
